[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Conditional              Test for Condition                    Statement Type

    Conditional statements test some condition, then choose a statement to
    execute as a result of that test. Pascal offers two conditionals:

     <if/then/else>   An IF/THEN/ELSE statement.

             <case>   A CASE statement.

    The first evaluates a Boolean expression: If TRUE, then a certain
    statement is executed; otherwise, it is skipped. Optionally, an
    alternative statement is executed if the expression is FALSE. In
    either case, execution continues with the statement following the
    IF/THEN/ELSE.

    The second evaluates an ordinal (Integer, Char, Boolean, enumerated
    data type) expression, then checks it against a list of values. If a
    match is made, then the statement associated with that value is
    executed. If no match is made, then none of the listed statements is
    executed. When done, execution continues with the statement that
    follows.

  -------------------------------- Example ---------------------------------

           if I = 0 then begin
             Word := Line;
             Line := ''
           end
           else begin
             Word := Copy(Line,1,I-1);
             Delete(Line,1,I)
           end;

           case Cmd of
             'N','E',S',W' : Move(Cmd);
             'I'           : DoInventory;
             'Q'           : QuitGame
           end;

See Also: if case
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson